From 493b98bf232159bef0a0f8d5955c04562c2c4108 Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Mon, 24 Oct 2005 14:11:07 +0100 Subject: [PATCH] Do not create the console tty until domain_create_ring has succeeded. This means that any reads attempted on that tty will not cause handle_tty_read to segfault looking for an interface that does not exist. Move the writing of the tty node so that it happens after console/limit has been read, as it is cleaner if the writing is the last thing that happens. Signed-off-by: Ewan Mellor --- tools/console/daemon/io.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 60e89267fc..0b55607d50 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -163,14 +163,6 @@ static int domain_create_tty(struct domain *dom) tcsetattr(master, TCSAFLUSH, &term); } - success = asprintf(&path, "%s/tty", dom->conspath) != -1; - if (!success) - goto out; - success = xs_write(xs, NULL, path, slave, strlen(slave)); - free(path); - if (!success) - goto out; - success = asprintf(&path, "%s/limit", dom->conspath) != -1; if (!success) goto out; @@ -180,6 +172,14 @@ static int domain_create_tty(struct domain *dom) free(data); } free(path); + + success = asprintf(&path, "%s/tty", dom->conspath) != -1; + if (!success) + goto out; + success = xs_write(xs, NULL, path, slave, strlen(slave)); + free(path); + if (!success) + goto out; } return master; @@ -269,6 +269,18 @@ static int domain_create_ring(struct domain *dom) } dom->local_port = rc; + if (dom->tty_fd == -1) { + dom->tty_fd = domain_create_tty(dom); + + if (dom->tty_fd == -1) { + err = errno; + close(dom->evtchn_fd); + dom->evtchn_fd = -1; + dom->local_port = -1; + goto out; + } + } + out: return err; } @@ -309,7 +321,7 @@ static struct domain *create_domain(int domid) dom->conspath = s; strcat(dom->conspath, "/console"); - dom->tty_fd = domain_create_tty(dom); + dom->tty_fd = -1; dom->is_dead = false; dom->buffer.data = 0; dom->buffer.size = 0; -- 2.30.2